<div id="information">
<br /><br />
<?php
if($_GET['mode']=="edit"){
   $select_news_red='SELECT * FROM news WHERE news_id='.$_GET['id'].'';
   $results_news_red=mysql_query($select_news_red);
		  
   $rows_news_red=mysql_fetch_assoc($results_news_red);
   
   ?>
    <form method="post" action="" class="form">
	<h3 class="form_h3">Заглавие:</h3>
	<p><input type="text" value="<?php echo $rows_news_red[news_name]; ?>" name="news" /></p>
	<h3 class="form_h3">Описание:</h3>
	<p><textarea cols="20" rows="3" name="descr_news"><?php echo $rows_news_red[news_descr]; ?></textarea></p>
	<h3 class="form_h3">Новина:</h3>
	<p><textarea name="myTextArea" id="myTextArea" cols="50" rows="7" ><?php echo $rows_news_red[content]; ?></textarea><br /><br /></p>
	<p><input type="submit" name="edit_news" value="Редактирай новината"/></p>
	</form>
   <?php
   include "../php/editnewsfile.php";
} elseif($_GET['mode']=="old"){
   ?>
   <div id="lastnews">
   <?php
   $sel_n = mysql_query('SELECT * FROM news ORDER BY date_added DESC');
   while($row_n = mysql_fetch_assoc($sel_n)){
   ?>
	<div class="box_lastnews">
	<?php
	   echo '<p><b><a href="seenews.php?id='.$row_n['news_id'].'" class="f">'.$row_n['news_name'];
	   echo '</a></b> - '.$row_n['news_descr'] . '</p>';
	   echo '<hr />';
       echo '<p>Дата на добавяне: <b>'.date('d/m/Y', $row_n['date_added']).'</b></p>';
	?>
	</div>
	<br />
	<?php
   }
   ?>
   </div>
   <?php
} else {
$sel_news = mysql_query('SELECT * FROM news WHERE news_id = '.$_GET['id'].'');
$row_news = mysql_fetch_assoc($sel_news);
?>
    <div style="border: 2px solid #333; width: 60px; border-radius: 4px; -moz-border-radius: 4px; -o-border-radius: 4px; -webkit-border-radius: 4px; height: 80px; box-shadow: 2px 2px 2px #000; margin-left: 20px;">
	<?php
	$select_date = mysql_query('SELECT * FROM news WHERE news_id = '.$_GET['id'].'');
	$row_news_from_id = mysql_fetch_assoc($select_date);
	
	echo '<p style="font-size: 12px; text-align: center; position: relative; top: -10px;">Качено:</p>';
	echo "<p style='font-size: 13px; position: relative; text-align: center; top: -15px'><b>".date('d-m', $row_news_from_id[date_added])."</b></p>";
	echo "<p style='font-size: 14px; position: relative; text-align: center; top: -20px'><b>".date('Y', $row_news_from_id[date_added])."</b></p>";
	?>
	</div>
    <div style="text-indent: 30px; width: 500px; text-align: left; float: right; position: relative; margin-right: 10px; top: -40px;">
	<?php
	echo $row_news_from_id['content'];
	echo "<br /><br />";
	echo "<p style='float: right; margin-right: 10px;'>Добавено от: <b> ".$row_news_from_id['from_who']."</b></p>";
	?>
	</div>
	<?php
	echo '<br /><br /><br />';
	}
	
	//Comments
   if($_GET['id']){
   $select_comments=mysql_query('SELECT * FROM comments_news WHERE id_news='.$_GET['id'].' ORDER BY date_added DESC');
   
   if(mysql_num_rows($select_comments)>0){
	
	echo '
	<h3 style="text-align: center;">Коментари</h3>
	<hr style="position: relative; top: -10px; width: 95%;"/>
	<table border="0" style="margin-left: 25px; margin-right: 25px; background-color: #fff; border-radius: 10px;">
	';
	
	while($row_comments=mysql_fetch_assoc($select_comments)){
	   $select_avatar=mysql_query('SELECT * FROM avatars WHERE from_who="'.$row_comments['from_who'].'"');
	   $row_avatar=mysql_fetch_assoc($select_avatar);
	   
	   if(mysql_num_rows($select_avatar)!=0){
	      $img1='<img src="../user_pics/'.$row_avatar[pic_name].'" width="110" height="110" style="margin-left: 10px; box-shadow: 5px 5px 5px #000" alt="avatar"/>';
	   }
	   else $img1 = '<img src="../user_pics/default.png" width="110" height="110" style="margin-left: 10px; box-shadow: 5px 5px 5px #000" alt="avatar"/>';
	   
	   echo '<tr><td style="background-color: #ccc; width: 150px;"><span style="margin-left: 25px;">Автор: <b>'.$row_comments['from_who'].'</b></span></td><td colspan="2" style="background-color: #ccc; width: 550px;"><span style="float: right; margin-right: 5px;">Добавен на: <b>'.date('d-m-Y', $row_comments[date_added]).'</b></span></td></tr>';
	   echo '<tr><td>'.$img1.'</td>';
	   echo '<td><p style="padding-bottom: 80px;">'.$row_comments['comment'].'</p>';
	   if($_SESSION['is_logged']==true && ($row_comments['from_who']==$_SESSION['username'] || $_SESSION['username']=="admin")){
	   echo '<a href="seenews.php?id='.$_GET['id'].'&amp;delete=delete&amp;c_id='.$row_comments['id'].'"><img src="../img/delete.png" style="float: right; width: 15px; height: 15px;" alt="delete_comment"/></a></td></tr>';
	   }
	   echo '<tr><td colspan="2"><hr style="border: 1px dashed #979AA1;"/></td></tr>';
	}
	
	echo '
	</table>
	'; 
	if($_GET['delete']=="delete"){
	$delete=mysql_query('DELETE FROM comments_news WHERE id_news='.$_GET['id'].' AND id='.$_GET['c_id'].'');
	echo '<meta http-equiv="refresh" content="0;url=seenews.php?id='.$_GET['id'].'">';
	}
	}
	if($_SESSION['is_logged']==true){
	?>
	<div class="form_comment">
	<form method="post" action="">
	<table border="0" id="text_area" style="border-collapse: collapse;">
	<tr><td colspan="2">
	<div style="margin-left: 15px; font-size: 14px;">Коментар:</div></td></tr>
	<tr><td><textarea cols="40" rows="5" id="comment_text" name="comment_text"></textarea></td>
	<td><input type="submit" value="Коментирай!" name="submit_comment" id="submit_comment" style="background-color: #fff; border-radius: 6px; -moz-border-radius: 6px;"/></td></tr>
	</table>
	</form>
	<br />
	</div>
	<?php
	}
	if($_POST['submit_comment']=="") echo "";
	else{
	   $comment=trim(addslashes(htmlspecialchars($_POST['comment_text'])));
	   if(empty($comment) || ($comment=="")){
	   
	   echo '
	   <script type="text/javascript">
	      alert("Моля, попълнете полето!");
	   </script>
	   ';
	   
	   } else {
	      if(strlen($comment)<=2){
		  
		  echo '
		  <script type="text/javascript">
	         alert("Коментарът трябва да има по-дълга дължина!");
	      </script>
		  ';
		  
		  } else {
			 $date_added=time();
			 $from_who=$_SESSION['username'];
			 $id_news=$_GET['id'];
			 $insert_comment=mysql_query('INSERT INTO comments_news(comment, date_added, from_who, id_news) 
			 VALUES("'.$comment.'", '.$date_added.', "'.$from_who.'", '.$id_news.')');
		     echo '<meta http-equiv="refresh" content="0;url=seenews.php?id='.$_GET['id'].'">';
		  }
	   }
	}
	} 
	?>
</div>